/**   
 * @Title: ProjectController.java 
 * @Package org.playgod1984.du.ddesign.controller 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author playgod playgod1984@163.com  
 * @date 2014年10月20日 下午5:18:05 
 * @version V1.0   
 */
package org.playgod1984.du.ddesign.controller;

import java.util.Map;

import org.playgod1984.du.auth.model.User;
import org.playgod1984.du.base.ApplicationController;
import org.playgod1984.du.ddesign.model.Project;
import org.playgod1984.du.ddesign.validator.ProjectValidator;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;

/** 
 * @ClassName: ProjectController 
 * @Description: TODO(这里用一句话描述这个类的作用) 
 * @author playgod playgod1984@163.com 
 * @date 2014年10月20日 下午5:18:05 
 *  
 */
@SuppressWarnings("all")
public class ProjectController extends ApplicationController {
	/**
	 * @Title: list
	 * @author:playgod playgod1984@163.com 
	 * @Description: Project List for request /design/project/list 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void list(){
		// direct to user_list.html
		render("/WEB-INF/views/ddesign/project/pro_list.html");
	}
	/**
	 * @Title: pagenate
	 * @author:playgod playgod1984@163.com 
	 * @Description: page query
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void pagenate(){
		Map params = getParamsMap();// get
		// Query All Project
		Project pj = getModel(Project.class);
		Page<Project> proList = pj.getProjectsWithPagenate(params);
		//Map whereMap = getDataGridFilter();
		renderJson("Rows", proList.getList());
	}
	/**
	 * @Title: g2add
	 * @author:playgod playgod1984@163.com 
	 * @Description: To Add
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2add(){
		setAttr("screen", "A");// update
		render("/WEB-INF/views/ddesign/project/pro_edit.html");
	}
	
	/**
	 * @Title: g2edit
	 * @author:playgod playgod1984@163.com 
	 * @Description: ADD,EDIT,VIEW PROJECT
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2edit(){
		Project pro = Project.dao.findById(getPara("projectcode"));
		setAttr("pro", pro);
		setAttr("screen", "E");// update
		render("/WEB-INF/views/ddesign/project/pro_edit.html");
	}
	/**
	 * @Title: save
	 * @author:playgod playgod1984@163.com 
	 * @Description: save project
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	@Before(ProjectValidator.class) 
	public void save(){
		Map params = getParamsMap();
		if(Project.dao.save(params)){
			renderJson(RES_SUCCESS);
		}else{
			renderJson(RES_FAILED);
		}
	}
	/**
	 * @Title: config
	 * @author:playgod playgod1984@163.com 
	 * @Description: Config Mumber 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void g2config(){
		Project pro = Project.dao.findById(getPara("projectcode"));
		setAttr("pro", pro);
		render("/WEB-INF/views/ddesign/project/pro_config.html");
	}
	/**
	 * @Title: config
	 * @author:playgod playgod1984@163.com 
	 * @Description: 已选用户
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void mumbers(){
		Map params = getParamsMap();
		Page<User> userList = Project.dao.getUserWithProject(params);
		renderJson("Rows", userList.getList());
	}
	/**
	 * @Title: users
	 * @author:playgod playgod1984@163.com 
	 * @Description: 未选用户
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void users(){
		Map params = getParamsMap();
		Page<User> userList = Project.dao.getUserWithoutProject(params);
		renderJson("Rows", userList.getList());
	}
	/**
	 * @Title: delete
	 * @author:playgod playgod1984@163.com 
	 * @Description: Delete Records
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void delete(){
		Map params = getParamsMap();
		int delRes = Project.dao.deleteRows(params);
		renderJson(delRes);
	}
	/**
	 * @Title: addMumber
	 * @author:playgod playgod1984@163.com 
	 * @Description: Config User
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void addMumber(){
		Map params = getParamsMap();
		if(Project.dao.addMumber(params)){
			renderJson(RES_SUCCESS);
		}else{
			renderJson(RES_FAILED);
		}
	}
	/**
	 * @Title: removeUser
	 * @author:playgod playgod1984@163.com 
	 * @Description: Remove User 
	 * @param     设定文件 
	 * @return void    返回类型 
	 * @throws
	 */
	public void removeMumber(){
		Map params = getParamsMap();
		if(Project.dao.removeMumber(params)){
			renderJson(RES_SUCCESS);
		}else{
			renderJson(RES_FAILED);
		}
	}
}
